﻿using SmartCity.BasicData.Common.Menus;

namespace SmartCity.BasicData.Common
{
    /// <summary>
    /// 接口响应公共类
    /// </summary>
    public class ApiResult<T> 
    {
        public ApiResult()
        {
        }
        public ApiResult(bool isSuc, string msg, T? data, EnumResultCode code)
        {
            //this.IsSuc = isSuc;
            this.Msg = msg;
            this.Data = data;
            this.Code = code;
        }
        //public bool IsSuc { get; set; }
        public string Msg { get; set; }
        public T? Data { get; set; }
        public EnumResultCode Code { get; set; }

        public ApiResult<T> Sussess(T? data , string msg = "操作成功")
        {
            return new ApiResult<T>(true, msg, data, EnumResultCode.Success);
        }

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ApiResult<T> Ok(T? data, string msg = "操作成功")
        {
            return new ApiResult<T>(true, msg, data, EnumResultCode.Success);
        }
        /// <summary>
        /// 失败返回
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult<T> Fail(T? data, string msg = "操作失败")
        {
            return new ApiResult<T>(false, msg, data, EnumResultCode.Success);
        }


    }
}
